{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "![Automekin.png]()\n",
        "# Automated reaction Mechanisms and Kinetics\n",
        "\n"
      ],
      "metadata": {
        "id": "vXtSvTouM1dG"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Installing third-party packages"
      ],
      "metadata": {
        "id": "9LmhQ0GeMi9z"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "%%capture\n",
        "!apt update\n",
        "!pip install --upgrade x3dase\n",
        "!apt install bc gawk gcc gfortran parallel sqlite3 cm-super dvipng texlive-latex-extra texlive-latex-recommended\n",
        "%cd /opt/\n",
        "!git clone https://github.com/dgarayr/amk_tools.git\n",
        "%cd /opt/amk_tools\n",
        "!pip install -e ."
      ],
      "metadata": {
        "id": "cQDTrDFQGe3p"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Installing AutoMeKin"
      ],
      "metadata": {
        "id": "qTg3nK8uNBMr"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "P6BRAe0KGS70"
      },
      "outputs": [],
      "source": [
        "%%capture\n",
        "%cd /content/\n",
        "!git clone https://github.com/emartineznunez/AutoMeKin.git\n",
        "%cd /content/AutoMeKin\n",
        "! autoreconf -i\n",
        "!./configure --prefix=/opt/AutoMeKin\n",
        "!make && make install\n",
        "#We make use of the total number of processors\n",
        "!sed -i 's@ignore=1@ignore=0@g' /opt/AutoMeKin/bin/utils.sh\n",
        "%env PATH=\".:/opt/amk_tools/scripts:/opt/AutoMeKin/bin:/opt/AutoMeKin/bin/HLscripts:/opt/AutoMeKin/bin/MOPAC_DEV:/opt/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin\"\n",
        "%env LIBRARY_PATH=\"/opt/AutoMeKin/lib:/opt/AutoMeKin/bin/MOPAC_DEV:/usr/local/cuda/lib64/stubs\"\n",
        "%env AMK=/opt/AutoMeKin\n",
        "%env inter=0\n",
        "%cd /content\n",
        "!rm -rf /content/AutoMeKin"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Running tests\n",
        "Running several tests. Further details: https://emartineznunez.github.io/AutoMeKin/docs/tutorial.html"
      ],
      "metadata": {
        "id": "FoE0ellxNoC-"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Association complexes**"
      ],
      "metadata": {
        "id": "uHT9VzrHIuxf"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Benzene (Bz)$-$N$_2$ complexes (Wall time: $\\approx$ 1 min)\n",
        "%%capture\n",
        "!run_test.sh --tests=assoc"
      ],
      "metadata": {
        "cellView": "form",
        "id": "K6_uQa8VctTT"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Visualization of the optimized Bz$-$N$_2$ structure\n",
        "%cd /content/assoc\n",
        "import IPython\n",
        "from x3dase.visualize import view_x3d_n\n",
        "from ase.io import read\n",
        "atoms = read('Bz-N2.xyz')\n",
        "view_x3d_n(atoms,output='molA.html', bond=1.0, label=True)\n",
        "IPython.display.HTML(filename='molA.html')"
      ],
      "metadata": {
        "id": "usMNIH3YfBFc",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Diels-Alder reaction**"
      ],
      "metadata": {
        "id": "tq8wwst-Kvjp"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Creating a local server\n",
        "import IPython\n",
        "from IPython.core.magic import register_line_magic\n",
        "import subprocess\n",
        "\n",
        "@register_line_magic\n",
        "def run_local_server(line):\n",
        "    handle = IPython.display.display(\n",
        "            IPython.display.Pretty(\"Launching my server...\"),\n",
        "            display_id=True,\n",
        "    )\n",
        "    subprocess.Popen(['python', '-m', 'http.server'])\n",
        "    shell = \"\"\"\n",
        "        (async () => {\n",
        "            const url = new URL(await google.colab.kernel.proxyPort(8000, {'cache': true}));\n",
        "            const iframe = document.createElement('iframe');\n",
        "            iframe.src = url;\n",
        "            iframe.setAttribute('width', '100%');\n",
        "            iframe.setAttribute('height', '800');\n",
        "            iframe.setAttribute('frameborder', 0);\n",
        "            document.body.appendChild(iframe);\n",
        "        })();\n",
        "    \"\"\"\n",
        "    script = IPython.display.Javascript(shell)\n",
        "    handle.update(script)"
      ],
      "metadata": {
        "cellView": "form",
        "id": "hyZg4rA5LhO7"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Diels-Alder rxn\n",
        "%%capture\n",
        "%cd /content\n",
        "!run_test.sh --tests=rdiels_bias"
      ],
      "metadata": {
        "id": "HqZRBSXfK13o",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Generate network.html for visualization\n",
        "%%capture\n",
        "%cd /content/rdiels_bias/\n",
        "%env iter=1\n",
        "%env inter=0\n",
        "!irc.sh\n",
        "!min.sh\n",
        "!rxn_network.sh\n",
        "!kmc.sh\n",
        "!final.sh\n",
        "!amk_gen_view.py FINAL_LL_rdiels RXNet --paths\n",
        "!mkdir HTML\n",
        "!mv network.html HTML\n",
        "%cd /content/rdiels_bias/HTML"
      ],
      "metadata": {
        "id": "24VR3FaMuGbH",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title _Open the file network.html_\n",
        "!fuser -k 8000/tcp\n",
        "%run_local_server"
      ],
      "metadata": {
        "id": "iHEVanJB1g2x",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **FA $\\rightarrow$ H$_2$+CO$_2$ chemical reaction**"
      ],
      "metadata": {
        "id": "VfNAcUTMJ9cW"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# @title FA $\\rightarrow$H$_2$+CO$_2$ rxn\n",
        "%%capture\n",
        "%cd /content\n",
        "!run_test.sh --tests=FA_biasH2"
      ],
      "metadata": {
        "cellView": "form",
        "id": "w_TwFbPlKJ3F"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Generate network.html for visualization\n",
        "%%capture\n",
        "%cd /content/FA_biasH2/\n",
        "%env iter=1\n",
        "%env inter=0\n",
        "!irc.sh\n",
        "!min.sh\n",
        "!rxn_network.sh\n",
        "!kmc.sh\n",
        "!final.sh\n",
        "!amk_gen_view.py FINAL_LL_FA RXNet --paths\n",
        "!mkdir HTML\n",
        "!mv network.html HTML\n",
        "%cd /content/FA_biasH2/HTML"
      ],
      "metadata": {
        "cellView": "form",
        "id": "OoNXGX6uKeLq"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title _Open the file network.html_\n",
        "!fuser -k 8000/tcp\n",
        "%run_local_server"
      ],
      "metadata": {
        "cellView": "form",
        "id": "zonnUO6-K0OA"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **FA $\\rightarrow$ H$_2$O+CO chemical reaction**"
      ],
      "metadata": {
        "id": "OktqvkjAosd8"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# @title FA $\\rightarrow$H$_2$O+CO rxn\n",
        "%%capture\n",
        "%cd /content\n",
        "!run_test.sh --tests=FA_biasH2O"
      ],
      "metadata": {
        "cellView": "form",
        "id": "c9yTrYqNo0m7"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Generate network.html for visualization\n",
        "%%capture\n",
        "%cd /content/FA_biasH2O/\n",
        "%env iter=1\n",
        "%env inter=0\n",
        "!irc.sh\n",
        "!min.sh\n",
        "!rxn_network.sh\n",
        "!kmc.sh\n",
        "!final.sh\n",
        "!amk_gen_view.py FINAL_LL_FA RXNet --paths\n",
        "!mkdir HTML\n",
        "!mv network.html HTML\n",
        "%cd /content/FA_biasH2O/HTML"
      ],
      "metadata": {
        "cellView": "form",
        "id": "9JTPVz5mo7Nd"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title _Open the file network.html_\n",
        "!fuser -k 8000/tcp\n",
        "%run_local_server"
      ],
      "metadata": {
        "cellView": "form",
        "id": "yFhXIGszpHQp"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Sampling conformational space**"
      ],
      "metadata": {
        "id": "zq1ESp5fv302"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Scanning torsions\n",
        "%%capture\n",
        "%cd /content\n",
        "!run_test.sh --tests=ttors"
      ],
      "metadata": {
        "id": "JnRTKCSdwCAo",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Generate network.html for visualization\n",
        "%%capture\n",
        "%cd /content/ttors/\n",
        "%env iter=1\n",
        "%env inter=0\n",
        "!cp ttors.xyz ttors_ref.xyz\n",
        "!irc.sh\n",
        "!min.sh\n",
        "!rxn_network.sh\n",
        "!kmc.sh\n",
        "!final.sh\n",
        "!amk_gen_view.py FINAL_LL_ttors RXNet --paths\n",
        "!mkdir HTML\n",
        "!mv network.html HTML\n",
        "%cd /content/ttors/HTML"
      ],
      "metadata": {
        "id": "Tw1pGwSgwSMj",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title _Open the file network.html_\n",
        "!fuser -k 8000/tcp\n",
        "%run_local_server"
      ],
      "metadata": {
        "id": "zjmPx2xawe92",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Decomposition of formic acid at $T=$ 300 and 5000 K**"
      ],
      "metadata": {
        "id": "sw6kV4rmpjh6"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# @title FA decomposition channels & Kinetics at two different temperatures\n",
        "%%capture\n",
        "%cd /content\n",
        "!run_test.sh --tests=FAthermo"
      ],
      "metadata": {
        "cellView": "form",
        "id": "zAh2-g0qrAcJ"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title _Kinetics@300K_\n",
        "%cd /content/FAthermo\n",
        "\n",
        "# importing libraries and creating the plot\n",
        "import pandas as pd\n",
        "from matplotlib import pyplot\n",
        "\n",
        "pyplot.rcParams['text.usetex'] = True\n",
        "pyplot.xticks(fontsize=14)\n",
        "pyplot.yticks(fontsize=14)\n",
        "\n",
        "data = pd.read_csv('FINAL_LL_FA_T300/kinetics.csv')\n",
        "for count,col in enumerate(data.columns):\n",
        "  if count == 0:\n",
        "    x=data[col]\n",
        "    xcol=col\n",
        "  if count >=1: pyplot.plot(x,data[col],label=col,linewidth=1.0)\n",
        "\n",
        "pyplot.ylabel('Population',fontsize=20)\n",
        "pyplot.xlabel(xcol,fontsize=20)\n",
        "\n",
        "pyplot.legend()\n",
        "pyplot.xlim(0,max(x))\n",
        "pyplot.ylim(0,1000)\n",
        "pyplot.tight_layout()\n",
        "pyplot.savefig('/content/FAthermo/kinetics300.png')\n",
        "pyplot.show()"
      ],
      "metadata": {
        "cellView": "form",
        "id": "2nT60qAPs0-U"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title _Kinetics@5000K_\n",
        "%cd /content/FAthermo\n",
        "\n",
        "# importing libraries and creating the plot\n",
        "import pandas as pd\n",
        "from matplotlib import pyplot\n",
        "\n",
        "pyplot.rcParams['text.usetex'] = True\n",
        "pyplot.xticks(fontsize=14)\n",
        "pyplot.yticks(fontsize=14)\n",
        "\n",
        "data = pd.read_csv('FINAL_LL_FA_T5000/kinetics.csv')\n",
        "for count,col in enumerate(data.columns):\n",
        "  if count == 0:\n",
        "    x=data[col]\n",
        "    xcol=col\n",
        "  if count >=1: pyplot.plot(x,data[col],label=col,linewidth=1.0)\n",
        "\n",
        "pyplot.ylabel('Population',fontsize=20)\n",
        "pyplot.xlabel(xcol,fontsize=20)\n",
        "\n",
        "pyplot.legend()\n",
        "pyplot.xlim(0,max(x))\n",
        "pyplot.ylim(0,1000)\n",
        "pyplot.tight_layout()\n",
        "pyplot.savefig('/content/FAthermo/kinetics5000.png')\n",
        "pyplot.show()"
      ],
      "metadata": {
        "cellView": "form",
        "id": "YZCiJCVrtcG-"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "source": [
        "## **Chemical Knowledge sampling**"
      ],
      "metadata": {
        "id": "xgXsaH1_IzEu"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# @title ChemKnow (be patient, this test takes $\\approx 5-7$ minutes)\n",
        "%cd /content\n",
        "!rm -rf FA_ck\n",
        "!run_test.sh --tests=FA_ck"
      ],
      "metadata": {
        "id": "cZ2ysrp0KrSL",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title Generate network.html for visualization\n",
        "%%capture\n",
        "%cd /content/FA_ck/\n",
        "!amk_gen_view.py FINAL_LL_FA RXNet --paths\n",
        "!mkdir HTML\n",
        "!mv network.html HTML\n",
        "%cd /content/FA_ck/HTML"
      ],
      "metadata": {
        "cellView": "form",
        "id": "knvjRTyxvG_9"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "# @title _Open the file network.html_\n",
        "!fuser -k 8000/tcp\n",
        "%run_local_server"
      ],
      "metadata": {
        "cellView": "form",
        "id": "FN5TTzvavYpG"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}